package win;

import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * ClassName: BubbleSort
 * Package: win
 * Description:
 * User: fzykd
 *
 * @Author: LQH
 * Date: 2023-08-21
 * Time: 19:53
 */

//冒泡排序
public class BubbleSort {
    public static void main(String[] args) {

        int[] arr = {4,5,2,6,8,9,1};


        for (int i = 0; i < arr.length - 1; i++) {
            for (int j = 0; j < arr.length - 1 - i; j++) {
                if (arr[j] > arr[j + 1]){
                    int tmp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = tmp;

                    //做一个标志位判断 如果没有交换 那么就说明已经有序了
                }
            }
        }

        System.out.println(Arrays.toString(arr));

    }
}
